// widgets/UserWidget/UserOrderWidget/UserOrderWidget.js
//获取应用实例
const app = getApp();
const assetsAddress = app.globalData.global.assetsIp + '/' + app.globalData.global.assetsName;

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pendingPayment: {
      type: Number,
      value: 0,
    }, // 待付款数量
    pendingDeliverGoods: {
      type: Number,
      value: 0,
    }, // 待发货数量
    pendingReceiving: {
      type: Number,
      value: 0,
    }, // 待收货数量
    pendingEvaluate: {
      type: Number,
      value: 0,
    }, // 待评价数量
  },

  /**
   * 组件的初始数据
   */
  data: {
    widgetList: [
      { id: '', name: '待付款', img: `${assetsAddress}/my/toBePaidIcon.png`, path: '/pages/Orders/Orders/Orders', type: '0', isPage: true},
      { id: '', name: '待发货', img: `${assetsAddress}/my/toBeShippedIcon.png`, path: '/pages/Orders/Orders/Orders', type: '1', isPage: true},
      { id: '', name: '待收货', img: `${assetsAddress}/my/toBeReceivedIcon.png`, path: '/pages/Orders/Orders/Orders', type: '2', isPage: true},
      { id: '', name: '待评价', img: `${assetsAddress}/my/toBeEvaluatedIcon.png`, path: '/pages/Goods/Evaluation/Evaluation', type: '3', isPage: true},
      { id: '', name: '退款/售后', img: `${assetsAddress}/my/saleAfterIcon.png`, path: '', type: '', isPage: false},
    ],
    contactUrl: app.globalData.global.contactUrl,
    contactId: app.globalData.global.contactId,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 页面跳转
    goNext(e){
      let item = e.target.dataset.item||e.currentTarget.dataset.item;
      // return
      if(item.isPage){
        if(item.type !== ''){
          wx.navigateTo({
            url: `${item.path}?type=${JSON.stringify(item.type)}`,
          })
        }else{
          wx.navigateTo({
            url: `${item.path}`,
          })
        }
      }else{
        let _this = this;
        wx.openCustomerServiceChat({
          extInfo: {
            url: _this.data.contactUrl,
          },
          corpId: _this.data.contactId,
        })
      }
    },
    goNexts(e){
      let url = e.target.dataset.name||e.currentTarget.dataset.name;
      wx.navigateTo({
        url: url,
      })
    },
  }
})
